﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DTS
{
    class AlgorithmMINMAX : Algorithm
    {
        int Period;
        public AlgorithmMINMAX(int days)
        {
            Period = days;
            this.name = "MINMAX" + days.ToString();
        }
        public AlgorithmMINMAX()
        {
            Period = 20;
            this.name = "MINMAX20";
        }
        public override int getDecision(HistoriaSpolki hs, DateTime Today)
        {
            var hsPrep = hs.getPrevOfData(Today, Period);
            Double min = double.MaxValue;
            Double max = double.MinValue;
            var dane = hsPrep.getDane();
            if (dane.Count == 0) return 0;
            for(int i=1;i<dane.Count;i++)
            {
                if (max < dane[i].GetClose()) max = dane[i].GetClose();
                if (min > dane[i].GetClose()) min = dane[i].GetClose();
            }
            if (dane[0].GetClose() > max) return 1;
            if (dane[0].GetClose() < min) return -1;
            return base.getDecision(hs, Today);
        }
        public override int getDecision(HistoriaSpolki hs, double cena, DateTime Today)
        {
            var hsPrep = hs.getPrevOfData(Today, Period);
            Double min = double.MaxValue;
            Double max = double.MinValue;
            var dane = hsPrep.getDane();
            if (dane.Count == 0) return 0;
            for (int i = 0; i < dane.Count; i++)
            {
                if (max < dane[i].GetClose()) max = dane[i].GetClose();
                if (min > dane[i].GetClose()) min = dane[i].GetClose();
            }
            if (cena > max) return 1;
            if (cena < min) return -1;
            return base.getDecision(hs, Today);
        }
    }
}
